package org.roy.uibase.field;

import java.util.Vector;

public abstract class Layout {
    protected Container iParent;
    protected Vector iChildren = new Vector();
    
    protected int[] iMargins = new int[4];
    
    public Layout(Container aParent){
        iParent = aParent;
    }
    
    public void addField(Field aField){
        iChildren.addElement(aField);
    }
    
    public void setMargins(int aLeftMargin, int aRightMargin, int aTopMargin, int aBottomMargin){
        iMargins[0] = aLeftMargin;
        iMargins[1] = aRightMargin;
        iMargins[2] = aTopMargin;
        iMargins[3] = aBottomMargin;
    }
    
    public void setMargin(int aMargin){
        iMargins[0] = aMargin;
        iMargins[1] = aMargin;
        iMargins[2] = aMargin;
        iMargins[3] = aMargin;
    }

    public Vector getChildren(){
        return iChildren;
    }
    
    public Field getField(int index){
        if(index > -1 && index < iChildren.size()){
            return (Field)(iChildren.elementAt(index));
        }
        
        return null;
    }
    
    public Field getFieldAt(int ax, int ay){
        for(int i= 0; i < iChildren.size(); i++){
            Field sField = (Field)iChildren.elementAt(i);
            if(sField.getBoundRect().contains(ax, ay)){
                return sField;             
            }
        }
        
        return null;
    }
    
    public abstract void layout();
   
}
